package com.esri.core.internal.tasks.e.a;

import com.esri.core.geometry.SpatialReference;
import java.io.Serializable;
import java.util.List;
import java.util.Stack;
import org.ksoap2.serialization.MarshalHashtable;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;

/* loaded from: classes.dex */
public class a extends com.esri.core.internal.tasks.e.a {
    public static final String c = "http://www.opengis.net/wms";
    public static final String d = "http://www.w3.org/1999/xlink";
    private static final long serialVersionUID = 1;
    private f e = null;
    private Stack<String> f = new Stack<>();
    private Stack<h> g = new Stack<>();
    private int h = 0;
    private C0017a i = null;

    /* renamed from: com.esri.core.internal.tasks.e.a.a$a  reason: collision with other inner class name */
    /* loaded from: classes.dex */
    class C0017a implements Serializable {
        private static final long serialVersionUID = 1;

        C0017a() {
        }

        public void a(String str) {
            a.this.a(str);
        }
    }

    public f a() {
        return this.e;
    }

    @Override // com.esri.core.internal.tasks.e.a, org.xml.sax.helpers.DefaultHandler, org.xml.sax.ContentHandler
    public void startElement(String str, String str2, String str3, Attributes attributes) {
        super.startElement(str, str2, str3, attributes);
        if (b(str)) {
            String a = a(str, str2, str3);
            this.f.push(a);
            if ("Layer".equals(a)) {
                h hVar = new h();
                if (!this.g.isEmpty()) {
                    this.g.lastElement().a(hVar);
                }
                this.g.push(hVar);
                if (this.h == 0) {
                    this.e.a(hVar);
                }
                this.h++;
            } else if (!this.g.isEmpty()) {
                this.g.lastElement().a(a, attributes);
            } else if ("WMS_Capabilities".equals(a)) {
                a(attributes);
            } else if ("WMT_MS_Capabilities".equals(a)) {
                a(attributes);
            } else if ("OnlineResource".equals(a)) {
                b(attributes);
            } else if ("Get".equals(a)) {
                c(attributes);
            } else if ("Format".equals(a)) {
                this.i = new C0017a();
            } else {
                C0017a c0017a = this.i;
                if (c0017a != null) {
                    c0017a.a(a);
                }
            }
        }
    }

    @Override // org.xml.sax.helpers.DefaultHandler, org.xml.sax.ContentHandler
    public void startDocument() throws SAXException {
        this.e = new f();
    }

    @Override // org.xml.sax.helpers.DefaultHandler, org.xml.sax.ContentHandler
    public void endDocument() throws SAXException {
        List<h> j = this.e.j();
        h hVar = j.get(j.size() - 1);
        this.e.a(a(hVar.a(), hVar, true, this.e.f()));
        a(hVar);
    }

    private void a(h hVar) {
        String b;
        if (hVar == null || hVar.a() == null || hVar.a().size() == 0) {
            return;
        }
        Stack stack = new Stack();
        stack.push(hVar);
        while (!stack.isEmpty()) {
            h hVar2 = (h) stack.pop();
            g a = a(hVar.a(), hVar2, false, this.e.f());
            if (a != null && (b = a.b()) != null) {
                int b2 = g.b(b);
                if (b2 != -1) {
                    hVar2.a(SpatialReference.create(b2));
                }
                if (g.a(this.e.f(), b)) {
                    hVar2.a(g.b(a.a()));
                } else {
                    hVar2.a(a.a());
                }
            }
            if (hVar2.j() != null && hVar2.j().size() > 0) {
                for (h hVar3 : hVar2.j()) {
                    stack.push(hVar3);
                }
            }
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:74:0x011d  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    com.esri.core.internal.tasks.e.a.g a(java.util.List<java.lang.String> r7, com.esri.core.internal.tasks.e.a.h r8, boolean r9, java.lang.String r10) {
        /*
            Method dump skipped, instructions count: 483
            To view this dump change 'Code comments level' option to 'DEBUG'
        */
        throw new UnsupportedOperationException("Method not decompiled: com.esri.core.internal.tasks.e.a.a.a(java.util.List, com.esri.core.internal.tasks.e.a.h, boolean, java.lang.String):com.esri.core.internal.tasks.e.a.g");
    }

    @Override // com.esri.core.internal.tasks.e.a, org.xml.sax.helpers.DefaultHandler, org.xml.sax.ContentHandler
    public void endElement(String str, String str2, String str3) {
        super.endElement(str, str2, str3);
        if (b(str)) {
            String pop = this.f.pop();
            if ("Layer".equals(pop)) {
                this.g.pop();
                this.h--;
            } else if (!this.g.isEmpty()) {
                this.g.lastElement().f(pop);
            } else if ("Format".equals(pop)) {
                this.i = null;
            }
        }
    }

    @Override // com.esri.core.internal.tasks.e.a, org.xml.sax.helpers.DefaultHandler, org.xml.sax.ContentHandler
    public void characters(char[] cArr, int i, int i2) {
        super.characters(cArr, i, i2);
        String trim = new String(cArr, i, i2).trim();
        if (this.g.isEmpty()) {
            if (this.f.isEmpty()) {
                return;
            }
            String lastElement = this.f.lastElement();
            if (lastElement.equals("Format")) {
                a(trim);
                return;
            } else if (lastElement.equals("Name")) {
                c(trim);
                return;
            } else if (lastElement.equals("Title")) {
                d(trim);
                return;
            } else if (lastElement.equals("Abstract")) {
                e(trim);
                return;
            } else {
                return;
            }
        }
        this.g.lastElement().a(cArr, i, i2);
    }

    private boolean b(String str) {
        return c.equals(str) || "".equals(str) || "http://www.w3.org/1999/xlink".equals(str);
    }

    void a(String str) {
        if (str == null || str.length() <= 0) {
            return;
        }
        if (this.f.contains("GetMap") || this.f.contains(MarshalHashtable.NAME)) {
            this.e.f(str);
        }
    }

    private void c(String str) {
        if (str == null || str.length() <= 0 || !this.f.contains("Service")) {
            return;
        }
        this.e.d(str);
    }

    private void d(String str) {
        if (str == null || str.length() <= 0 || !this.f.contains("Service")) {
            return;
        }
        this.e.e(str);
    }

    private void e(String str) {
        if (str == null || str.length() <= 0 || !this.f.contains("Service")) {
            return;
        }
        this.e.c(str);
    }

    private void a(Attributes attributes) {
        String[] a = a(attributes, "version", "updateSequence");
        if (a[0] == null || a[0].trim().length() <= 0) {
            return;
        }
        this.e.b(a[0]);
    }

    private void b(Attributes attributes) {
        String a = a(attributes, "xlink:href");
        if (a == null) {
            a = a(attributes, "href");
        }
        if (a == null || a.trim().length() <= 0) {
            return;
        }
        String trim = a.trim();
        if (this.f.contains("GetMap") || this.f.contains(MarshalHashtable.NAME)) {
            this.e.a(trim);
        }
    }

    private void c(Attributes attributes) {
        String a = a(attributes, "onlineResource");
        if (a == null || a.trim().length() <= 0) {
            return;
        }
        String trim = a.trim();
        if (this.f.contains("GetMap") || this.f.contains(MarshalHashtable.NAME)) {
            this.e.a(trim);
        }
    }
}
